﻿@{
    Layout = "~/Views/Shared/_AddEdit.cshtml";
}
@section header{
    <style>
        #form1 {
            max-width: none !important;
        }

        .colorBut {
            border-radius: 50%;
            width: 2rem;
            height: 2rem;
            border: solid 2px #fff;
        }

        .colorSelect {
            border: solid 2px #333;
        }

        .week {
            display: inline-block;
            margin-top: 5px;
        }
    </style>
}
<div class="poppan">
    <input type="hidden" name="_classRoomId" value="@ViewBag.Data["ClassRoomId"]" />
    <input type="hidden" name="_timeId" value="@ViewBag.Data["timeId"]" />
    <input type="hidden" name="_color" id="_color" value="@ViewBag.Data["color"]" />
    <input type="hidden" name="_guid" id="_guid" value="@ViewBag.Guid" />
    <table>
        <tr>
            <td width="50%" style="min-width:550px;">
                <table>
                    <tr>
                        <td width="80px">上课教室*</td>
                        <td width="120px"><input type="text" name="classRoom" class="layui-input" disabled value="@ViewBag.Data["ClassRoomName"]"></td>
                        <td width="80px">上课时段*</td>
                        <td width="120px"><input type="text" name="time" class="layui-input" disabled value="@ViewBag.Data["startTime"]-@ViewBag.Data["endTime"]"></td>
                    </tr>
                    <tr>
                        <td>课程系列*</td>
                        <td>
                            <select id="courseClass" lay-filter="courseClass">
                                @foreach (var dr in ViewBag.CourseClass)
                                {
                                    <option value="@dr["id"]" @(dr["id"] == ViewBag.ClassRoomId ? "selected" : "")>@dr["name"]</option>
                                }
                            </select>
                        </td>
                        <td>课程*</td>
                        <td>
                            <select name="_courseId" id="_courseId"></select>
                        </td>
                    </tr>
                    <tr>
                        <td>班级名称*</td>
                        <td><input type="text" name="_className" autocomplete="off" class="layui-input" value="@ViewBag.Data["className"]"></td>
                        <td>学员人数*</td>
                        <td><input type="text" name="_StudentNumber" autocomplete="off" class="layui-input" value="@ViewBag.Data["StudentNumber"]"></td>
                    </tr>
                    <tr>
                        <td>主教老师*</td>
                        <td>
                            <select name="_TeacherId">
                                @foreach (var dr in ViewBag.Teacher)
                                {
                                    <option value="@dr["id"]" @(dr["id"].ToString() == ViewBag.Data["TeacherId"].ToString() ? "selected" : "")>@dr["name"]</option>
                                }
                            </select>
                        </td>
                        <td>助教老师</td>
                        <td>
                            <select name="_TwoTeacherId">
                                <option value="0"></option>
                                @foreach (var dr in ViewBag.Teacher)
                                {
                                    <option value="@dr["id"]" @(dr["id"].ToString() == ViewBag.Data["TwoTeacherId"].ToString() ? "selected" : "")>@dr["name"]</option>
                                }
                            </select>
                        </td>
                    </tr>
                    <tr>
                        <td>上课开始-结束日期*</td>
                        <td><input type="text" name="_TeachDate" id="_TeachDate" autocomplete="off" class="layui-input" value="@ViewBag.Data["TeachDate"].ToString("yyyy-MM-dd") - @ViewBag.Data["TeachDate"].ToString("yyyy-MM-dd")"></td>
                        <td>可排人数*</td>
                        <td><input type="text" name="_LineUpNumber" autocomplete="off" class="layui-input" value="@ViewBag.Data["LineUpNumber"]"></td>
                    </tr>
                    <tr>
                        <td>星期选择*</td>
                        <td colspan="3">

                            <div class="week"><input type="checkbox" name="_week" id="_week1" value="1" title="星期一" @(ViewBag.week == DayOfWeek.Monday ? "checked" : "")></div>
                            <div class="week"><input type="checkbox" name="_week" id="_week2" value="2" title="星期二" @(ViewBag.week == DayOfWeek.Tuesday ? "checked" : "")></div>
                            <div class="week"><input type="checkbox" name="_week" id="_week3" value="3" title="星期三" @(ViewBag.week == DayOfWeek.Wednesday ? "checked" : "")></div>
                            <div class="week"><input type="checkbox" name="_week" id="_week4" value="4" title="星期四" @(ViewBag.week == DayOfWeek.Thursday ? "checked" : "")></div>
                            <div class="week"><input type="checkbox" name="_week" id="_week5" value="5" title="星期五" @(ViewBag.week == DayOfWeek.Friday ? "checked" : "")></div>
                            <div class="week"><input type="checkbox" name="_week" id="_week6" value="6" title="星期六" @(ViewBag.week == DayOfWeek.Saturday ? "checked" : "")></div>
                            <div class="week"><input type="checkbox" name="_week" id="_week7" value="7" title="星期日" @(ViewBag.week == DayOfWeek.Sunday ? "checked" : "")></div>
                        </td>
                    </tr>
                    <tr>
                        <td>颜色选择*</td>
                        <td colspan="3">
                            <div class="layui-row">
                                <div class="colorBut @(ViewBag.Data["color"].ToString()=="#f39d11"?"colorSelect":"")" style="background-color: #f39d11;float:left;"></div>
                                <div class="colorBut @(ViewBag.Data["color"].ToString()=="#ff8519"?"colorSelect":"")" style="background-color: #ff8519;float:left;margin-left:0.3rem"></div>
                                <div class="colorBut @(ViewBag.Data["color"].ToString()=="#de4939"?"colorSelect":"")" style="background-color: #de4939;float:left;margin-left:0.3rem"></div>
                                <div class="colorBut @(ViewBag.Data["color"].ToString()=="#00a75a"?"colorSelect":"")" style="background-color: #00a75a;float:left;margin-left:0.3rem"></div>
                                <div class="colorBut @(ViewBag.Data["color"].ToString()=="#12b9ac"?"colorSelect":"")" style="background-color: #12b9ac;float:left;margin-left:0.3rem"></div>
                            </div>
                            <div class="layui-row" style="margin-top:0.3rem">
                                <div class="colorBut @(ViewBag.Data["color"].ToString()=="#00c1ef"?"colorSelect":"")" style="background-color: #00c1ef;float:left;"></div>
                                <div class="colorBut @(ViewBag.Data["color"].ToString()=="#71afd3"?"colorSelect":"")" style="background-color: #71afd3;float:left;margin-left:0.3rem"></div>
                                <div class="colorBut @(ViewBag.Data["color"].ToString()=="#3c8cbd"?"colorSelect":"")" style="background-color: #3c8cbd;float:left;margin-left:0.3rem"></div>
                                <div class="colorBut @(ViewBag.Data["color"].ToString()=="#5f5ba9"?"colorSelect":"")" style="background-color: #5f5ba9;float:left;margin-left:0.3rem"></div>
                                <div class="colorBut @(ViewBag.Data["color"].ToString()=="#f117bf"?"colorSelect":"")" style="background-color: #f117bf;float:left;margin-left:0.3rem"></div>
                            </div>
                        </td>
                    </tr>
                </table>
            </td>
            <td width="width:10px;"></td>
            <td valign="top" style="padding-top:10px;">
                <button class="layui-btn layui-btn-primary " style="margin-left:1rem" onclick="openStudent();return false;"><span style="font-size:14px;line-height:2rem;height:2rem">+添加学员</span></button>
                <button class="layui-btn layui-btn-primary " style="margin-left:1rem" onclick="openStudentGroup();return false;"><span style="font-size:14px;line-height:2rem;height:2rem">+添加学员组</span></button>
                <fieldset class="layui-elem-field layui-field-title" style="margin-top: 20px;">
                    <legend>上课学员列表</legend>
                </fieldset>
                <table class="layui-table" lay-filter="dgrid" id="dgrid">
                    <thead>
                        <tr>
                            <th lay-data="{field:'custname',sort:true}">宝宝姓名</th>
                            <th lay-data="{field:'custmonth',sort:true}">月龄</th>
                            <th lay-data="{field:'linkname',sort:true}">家长姓名</th>
                            <th lay-data="{field:'custtel',sort:true}">联系电话</th>
                            <th lay-data="{field:'signupclass',sort:true}">上课类型</th>
                            <th lay-data="{align:'center', toolbar: '#messageBar'}">操作</th>
                        </tr>
                    </thead>
                </table>
            </td>
        </tr>
    </table>
</div>

<script type="text/html" id="messageBar">
    <a class="layui-btn layui-btn-xs" lay-event="do">退课</a>
</script>

@section fooler{
    <script>
    var guid = '@ViewBag.Guid';
    function openStudent() {
        var index = layui.layer.open({
            type: 2,
            content: '../ManagerLay?type=CourseStudent&guid=' + guid + '&courseId=' + $("#_courseId").val(),
            title: '选择学员',
            maxmin: true
        });
        layui.layer.full(index);
    }
    function openStudentGroup() {
        var index = layui.layer.open({
            type: 2,
            content: '../ManagerLay?type=Group&guid=' + guid + '&courseId=' + $("#_courseId").val(),
            title: '学员分组',
            maxmin: true
        });
        layui.layer.full(index);
    }

    layui.use(['element', 'table', 'layer', 'laypage', 'form', 'laydate'], function () {
        layui.laydate.render({
            elem: '#_TeachDate',
            range: true

        });
        layui.form.on('select(courseClass)', function (data) {
            SetCourse(data.value);
        });

        SetCourse($("#courseClass").val());

        //学生数据
        layui.table.init("dgrid", {
            url: '../Schedule/Course/StudentData?guid=' + guid,
            id: 'dgrid'
        });
        //监听工具条 退课操作
        layui.table.on('tool(dgrid)', function (obj) {
            var data = obj.data;
            if (obj.event === 'do') {
                $.ajax({
                    type: 'POST',
                    url: '../Schedule/Course/DelStudent',
                    data: {
                        id: data.id,
                        guid: guid,
                        t: new Date().getTime()
                    },
                    dataType: "json",
                    success: function (data) {
                        layui.layer.msg(data.message);
                        if (data.code == "0000") {
                            layui.table.reload("dgrid");
                        }
                    }
                });
            }
        });
    });
    function SetCourse(classId) {//视听课程
        $.ajax({
            type: 'POST',
            url: '../Schedule/Course/CourseData',
            data: { id: classId },
            dataType: "json",
            success: function (data) {
                if (data.code == "0000") {
                    var oldId = '@ViewBag.Data["courseId"]';
                    var courseId = $("#_courseId");
                    courseId.empty();
                    for (var i = 0; i < data.data.length; i++) {
                        var dr = data.data[i];
                        if (dr.id == oldId)
                            courseId.append("<option value='" + dr.id + "' selected>" + dr.coursename + "</option>");
                        else
                            courseId.append("<option value='" + dr.id + "'>" + dr.coursename + "</option>");
                    }
                    layui.form.render('select');
                }
                else
                    layui.layer.msg(data.message);
            }
        });
    }
    $(function () {
        $(".colorBut").click(function () {
            $(".colorBut").removeClass("colorSelect");
            $(this).addClass("colorSelect");

            var rgb = $(this).css('background-color');
            if (!rgb>=0) {
                rgb = rgb.match(/^rgb\((\d+),\s*(\d+),\s*(\d+)\)$/);
                function hex(x) {
                    return ("0" + parseInt(x).toString(16)).slice(-2);
                }
                rgb = "#" + hex(rgb[1]) + hex(rgb[2]) + hex(rgb[3]);
            }
            $("#_color").val(rgb);
        })
    })

    function ShowStudent() {
        layui.layer.closeAll();
        layui.table.reload("dgrid");
    }
    function SaveSuccessCallBack(res) {
        layui.layer.msg(res.message, {
            time: 500
        }, function () {
            parent.Reload();
            parent.HideModal("");
        });
        return true;
    }
    </script>
}
